package database.util;

import patient.Patient;

public class SQLPatinet {
    public static final String TABLE_NAME = "APP.\"Patient\"";

    public static final String W_ID_PATIENT = "id_pacjenta";
    public static final String W_NAME = "imie";
    public static final String W_SURNAME = "nazwisko";
    public static final String W_SEX = "plec";
    public static final String W_IS_INSURED = "czyUbezpieczony";
    public static final String W_PROFESSION = "zawod";

    public static String selectAllQueery() {
        return "SELECT * FROM " + TABLE_NAME;
    }

    public static String getSavePatientQuery(Patient patient) {
        int czyUbez;
        if (patient.isCzyUbezpieczony()) czyUbez = 1;
        else czyUbez = 0;

        String query = "INSERT INTO " + TABLE_NAME +
                "(" + W_NAME + "," +
                W_SURNAME + "," +
                W_SEX + "," +
                W_IS_INSURED + "," +
                W_PROFESSION + ") VALUES ('" +
                patient.getImie() + "','" +
                patient.getNazwisko() + "', '" +
                patient.getPlec() + "'," +
                czyUbez + ",'" +
                patient.getZawod().getNameToDB() + "')";

        return query;
    }

    public static String getDeletePatientQuery(Patient patient) {
        return "DELETE FROM " + TABLE_NAME + " WHERE " + W_ID_PATIENT + "=" + patient.getId();
    }

    public static String getUpdatePatientQuery(int id, Patient patient) {
        int czyUbez;
        if (patient.isCzyUbezpieczony()) czyUbez = 1;
        else czyUbez = 0;

        String query = "UPDATE " + TABLE_NAME + " SET " +
                W_NAME + "='" + patient.getImie() + "', " +
                W_SURNAME + "='" + patient.getNazwisko() + "', " +
                W_SEX + "='" + patient.getPlec() + "', " +
                W_IS_INSURED + "=" + czyUbez + ", " +
                W_PROFESSION + "='" + patient.getZawod().getNameToDB() + "' " +
                "WHERE " + W_ID_PATIENT + "=" + id;

        return query;
    }
}
